{% extends "base.html" %}

{% block title %}{{ course.name }}的成绩详情{% endblock %}

{% block content %}
<div class="container">
    <div class="row mb-4">
        <div class="col-md-12">
            <h1 class="display-5">{{ course.name }} ({{ course.course_id }}) 的成绩详情</h1>
            <div class="text-muted">授课教师: {{ course.teacher }} | 学分: {{ course.credit }}</div>
        </div>
    </div>
    
    <!-- 总体统计 -->
    <div class="row mb-5">
        <div class="col-md-4">
            <div class="card bg-primary text-white">
                <div class="card-body">
                    <h5 class="card-title">选课人数</h5>
                    <p class="card-text display-4">{{ scores|length }}</p>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card bg-success text-white">
                <div class="card-body">
                    <h5 class="card-title">平均分</h5>
                    <p class="card-text display-4">{{ "%.2f"|format(avg_score) }}</p>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card bg-info text-white">
                <div class="card-body">
                    <h5 class="card-title">最高分/最低分</h5>
                    <p class="card-text display-4">{{ max_score }}/{{ min_score }}</p>
                </div>
            </div>
        </div>
    </div>
    
    <!-- 成绩表格 -->
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-striped table-hover">
                            <thead>
                                <tr>
                                    <th>学生姓名</th>
                                    <th>学号</th>
                                    <th>班级</th>
                                    <th>成绩</th>
                                    <th>成绩等级</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for score in scores %}
                                <tr>
                                    <td>{{ score.student.name }}</td>
                                    <td>{{ score.student.student_id }}</td>
                                    <td>{{ score.student.class_name }}</td>
                                    <td>
                                        {% if score.score >= 90 %}
                                        <span class="text-success font-weight-bold">{{ score.score }}</span>
                                        {% elif score.score >= 80 %}
                                        <span class="text-primary font-weight-bold">{{ score.score }}</span>
                                        {% elif score.score >= 70 %}
                                        <span class="text-info font-weight-bold">{{ score.score }}</span>
                                        {% elif score.score >= 60 %}
                                        <span class="text-warning font-weight-bold">{{ score.score }}</span>
                                        {% else %}
                                        <span class="text-danger font-weight-bold">{{ score.score }}</span>
                                        {% endif %}
                                    </td>
                                    <td>
                                        {% if score.score >= 90 %}
                                        <span class="badge bg-success">优秀</span>
                                        {% elif score.score >= 80 %}
                                        <span class="badge bg-primary">良好</span>
                                        {% elif score.score >= 70 %}
                                        <span class="badge bg-info">中等</span>
                                        {% elif score.score >= 60 %}
                                        <span class="badge bg-warning">及格</span>
                                        {% else %}
                                        <span class="badge bg-danger">不及格</span>
                                        {% endif %}
                                    </td>
                                    <td>
                                        {% if current_user.role in ['admin', 'teacher'] %}
                                        <a href="{{ url_for('edit_score', id=score.id) }}" class="btn btn-sm btn-info">
                                            <i class="fas fa-edit me-1"></i>编辑
                                        </a>
                                        {% endif %}
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}